<template>
  <div id="centerLeft1">
    <div class="left-row1">
      <div class="left-content01">
        <div class="content01-hander row1-title">
          <img src="../../../public/imgs/Frame11.png" alt="">
          慧商管成访问量数据
          <div class="time_box">
            <div v-for="item in time " :key="item.id">
              <button :class="[item.id == index ? 'active' : 'default']" @click="get_visit(item.id)">{{ item.name
                }}</button>
            </div>
          </div>
        </div>
        <div class="content-item">
          <div class="zhihui-box">
            <visit :visit_data="visit_data" />
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import visit from "./visit.vue"
export default {
  data() {
    return {
      time: [
        { id: 1, name: '周' },
        { id: 2, name: '月' },
        { id: 3, name: '年' }
      ],
      index: 1,

      visit_data: {},
      optionsData: [],
    }
  },
  components: {
    visit
  },
  created() {
    this.fetchData()

  },
  mounted() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.$axios.post('/api/survey/visits', {
        yuenian: this.index
      })
        .then(res => {
          const data = res.data.data;
          this.visit_data = data;
        })
        .catch(error => {
          console.error('Failed to fetch chart data:', error);
        });
      this.$axios.post('/api/survey/nameGender')
        .then((response) => {
          this.optionsData = response.data.data;
          console.log("Fetched data:", this.optionsData);
        })
        .catch((error) => {
          console.error('Error fetching data:', error);
        });
    },
    get_visit(id) {
      this.index = id
      this.fetchData()
    }
  }
}
</script>

<style lang="scss" scoped>
$box-width: 572px;
$box-height: 294px;

#centerLeft1 {
  height: $box-height;
  width: $box-width;

  .left-row1 {
    width: 100%;
    height: 100%;
    display: flex;
    background-image: url("/public/imgs/LeftOne.png");
    background-repeat: no-repeat;
    background-size: cover;
  }

  .zhihui {
    cursor: default;
  }

  .content-item {
    display: flex;

    .zhihui-box {
      width: 520px;
      height: 300px;
    }

    // .zhihui-box>:nth-child(1) {
    //   margin-right: 8px;
    // }

  }

  .content01-hander {
    background: linear-gradient(to bottom, #FFFFFF, #97CDFF);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
    height: 45px;
    font-family: Adobe Heiti Std;
    font-weight: 600;
    font-size: 20px;
    color: #FFFFFF;
    display: flex;
    align-items: center;
    color: #fff;
    padding-left: 16px;
    padding-top: 16px;
    line-height: 40px;

    img {
      margin-right: 20px;
    }
  }
}

.time_box {
  display: flex;
  margin-left: 15px;

  div {
    width: 43px;
    height: 25px;
    line-height: 25px;
    margin-right: 5px;
    box-sizing: border-box;

    button {
      width: 100%;
      height: 100%;
      cursor: pointer;
      border: none;
      outline: none;
      background-color: transparent;
      font-size: 12px;
    }

    .active {
      background-image: url("../../../public/imgs/sadsadsadsagdsf.png");
      background-repeat: no-repeat;
      background-size: 100% 100%;
    }

    .default {
      background-image: url("../../../public/imgs/assasadsadsa.png");
      background-repeat: no-repeat;
      background-size: 100% 100%;
    }
  }
}
</style>
